#include<bits/stdc++.h>
#define int long long
#define ls(x) ((x)*2)
#define rs(x) ((x)*2+1)
#define Debug(...) fprintf(stderr, __VA_ARGS__)
#define For(i,a,b) for(int i=a,i##end=b;i<=i##end;i++)
#define Rof(i,a,b) for(int i=a,i##end=b;i>=i##end;i--)
using namespace std;
const int N=2e6+5,Mod=998244353;
//typedef __int128_t i128;
//i128 _base=1;
//inline int mol(int x){return x-Mod*(_base*x>>64);}
//inline void Add(int &x,int y){x=mol(x+y+Mod);}
inline int read(){
	int f=0,x=0;
	char ch=getchar();
	while(!isdigit(ch)){f|=(ch=='-');ch=getchar();}
	while(isdigit(ch)){x=(x<<3)+(x<<1)+(ch^48);ch=getchar();}
	return f?-x:x;
}
int n,rk[N],mn[N];
int s[N];
int vis[N];
bool flag;
inline bool chk(int x);
inline bool check(){
	For(i,1,n-1){
		For(j,0,n){
//			cout<<rk[i]<<" "<<rk[i+1]<<endl;
//			cout<<s[rk[i]+j]<<" "<<s[rk[i+1]+j]<<endl;
			if(s[rk[i]+j]>s[rk[i+1]+j]) return 0;
			if(s[rk[i]+j]<s[rk[i+1]+j]) break;
			
		}
	}
	
//			For(i,1,n) cout<<(char)(s[i]+'a'-1);
//			puts("");
	For(i,1,2*n-1){
		For(j,0,(mn[i]+1)/2-1){
			if(i%2==0){if(i/2-j+1<=0||i/2+j>n||s[i/2-j]!=s[i/2+1+j]){
//				puts("1");
//				For(i,1,n) cout<<(char)(s[i]+'a'-1);
//				puts("");
				return 0;
			}}
			else if(i/2+1-j<=0||i/2+1+j>n||s[i/2+1-j]!=s[i/2+1+j]){
//			cout<<i/2+1<<" "<<j<<" ";puts("2");
//			For(i,1,n) cout<<(char)(s[i]+'a'-1);
//			puts("");
				return 0;
			}
		}
		For(j,(mn[i]+1)/2,(mn[i]+1)/2){
			if(i%2==0){if(i/2-j+1>=1&&i/2+j<=n&&s[i/2-j]==s[i/2+1+j]){
				return 0;
			}}
			else if(i/2+1-j>=1&&i/2+1+j<=n&&s[i/2+1-j]==s[i/2+1+j]){
				return 0;
			}
		}
	}
	return 1;
}
void dfs(int x){
	if(flag) return;
	if(x==n+1){
	For(i,1,n) if(vis[i]==0&&vis[i+1]) return;
		if(check()){
			For(i,1,n) cout<<(char)(s[i]+'a'-1);
			puts("");
			flag=1;
			return;
		}
		return ;
	}
	For(i,1,n){
		s[x]=i;
		vis[i]++;
		dfs(x+1);
		vis[i]--;
	}
}
int tot=0;
int as[N],top[N];
const int base=999983;
int mi[N],hsh[N],ni[N];
int hsh2[N];
inline int ksm(int a,int b,int mod=Mod){
	int res=1;
	while(b){
		if(b&1) res=res*a%mod;
		a=a*a%mod;
		b>>=1;
	}
	return res;
}
inline int geth(int l,int r){
	return (hsh[r]-hsh[l-1]*mi[r-l+1]%Mod+Mod)%Mod;
}
inline int geth2(int l,int r){
	l=n-l+1;r=n-r+1;
	swap(l,r);
	return (hsh2[r]-hsh2[l-1]*mi[r-l+1]%Mod+Mod)%Mod;
}
inline bool chk(int x){
	For(i,1,n) if(top[i]<=x) s[i]=1;
	else s[i]=2;
	For(i,1,n) hsh[i]=(hsh[i-1]*base+s[i])%Mod;
	For(i,1,n) hsh2[i]=(hsh2[i-1]*base+s[n-i+1])%Mod;
	
	/*For(i,1,n-1){
		For(j,0,n){
//			cout<<rk[i]<<" "<<rk[i+1]<<endl;
//			cout<<s[rk[i]+j]<<" "<<s[rk[i+1]+j]<<endl;
			if(s[rk[i]+j]>s[rk[i+1]+j]) return 0;
			if(s[rk[i]+j]<s[rk[i+1]+j]) break;
			
		}
	}*/
//	cout<<geth(1,2)<<" "<<geth(2,3)<<endl;
	For(i,1,n-1){
		int l=0,r=n;
		int p=0;
		while(l<=r){
			int mid=(l+r)>>1;
//			cout<<mid<<endl;
			if(geth(rk[i],rk[i]+mid)==geth(rk[i+1],rk[i+1]+mid)) l=mid+1,p=mid+1;
			else r=mid-1;
		}
//		cout<<rk[i]<<" "<<rk[i+1]<<" "<<p<<endl;
		if(s[rk[i]+p]>s[rk[i+1]+p]) return 0;
	}
	For(i,1,2*n-1){
		int l=0,r=i/2+1;
		int p=0;
		if(i%2==1)
		while(l<=r){
			int mid=(l+r)>>1;
			if(geth2(i/2+1-mid,i/2+1)==geth(i/2+1,i/2+1+mid)) l=mid+1,p=mid*2+1;
			else r=mid-1;
		}
		else
		while(l<=r){
			int mid=(l+r)>>1;
			if(geth2(i/2-mid,i/2)==geth(i/2+1,i/2+1+mid)) l=mid+1,p=mid*2+2;
			else r=mid-1;
		}
		if(p!=mn[i]) return 0;
	}
	return 1;
}
inline void solve(){
	flag=0; 
	n=read();
	For(i,1,n) rk[i]=read()+1,top[rk[i]]=i;
	For(i,1,2*n-1) mn[i]=read();
//	s[1]=4,s[2]=5,s[3]=4,s[4]=4,s[5]=1,s[6]=3,s[7]=2,s[8]=6;
//	chk(1); 
//	return; 
	if(n<=8){
		dfs(1);
		if(!flag) puts("-1");
		return;
	} 
	bool bk=0;
	For(i,1,n) if(rk[i]!=n-i+1) bk=1;
	if(!bk){
		tot=0;
		For(i,1,2*n-1){
			if(mn[i]>mn[i-1]&&mn[i]>mn[i+1]) as[++tot]=mn[i];
		}
		if(tot>26){puts("-1");return;}
		int ts=0;
		For(i,1,tot) ts+=as[i];
		if(ts!=n){puts("-1");return;} 
		For(i,1,tot){
			For(j,1,as[i]) printf("%c",tot-i+'a');
		}
		puts("");
		return ;
	}
	Rof(i,n,1){
		if(chk(i)){
			For(j,1,n) if(top[j]<=i) putchar('a');
			else putchar('b');
			flag=1;
			break;
		}
	}
	if(!flag)puts("-1");
}
signed main(){
	//_base=(_base<<64)/Mod;
	freopen("string.in","r",stdin);
	freopen("string.out","w",stdout);
	// ios::sync_with_stdio(false);
	// cin.tie(0); cout.tie(0);
	mi[0]=ni[0]=1;
	ni[1]=ksm(base,Mod-2);
	For(i,1,N-5) mi[i]=mi[i-1]*base%Mod;
	For(i,2,N-5) ni[i]=ni[i-1]*ni[1]%Mod; 
	int T=read();
	while(T--) solve();
#ifdef LOCAL
    Debug("\nMy Time: %.3lfms\n", (double)clock() / CLOCKS_PER_SEC);
#endif
	return 0;
}
/*

3
8
4 6 5 3 2 0 1 7
1 0 3 0 1 0 1 0 1 0 1 0 1 0 1
8
2 5 7 0 4 3 6 1
1 0 1 0 1 0 1 0 1 0 1 0 1 0 1
8
2 1 5 4 0 3 6 7
2 1 6 8 7 3 13 13 6 3 22 17 14 14 10

*/
